package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import client.Client;
import client.Item;

public class Order1 extends JFrame{

	final public static int DEFAULT_PORT = 5555;
	protected static final String String = null;	
    private String host = MainPanel.ip; 
	private int orderflag;
    
    public Order1(int orderflag) throws HeadlessException {
		super();
		initialize();
		this.orderflag = orderflag;
	}

	public Order2 order2;  //  @jve:decl-index=0:visual-constraint="10,820"
    public Order3 order3;  //  @jve:decl-index=0:visual-constraint="10,1624"
    public Order1 ord;
	private String[] Orderinfo;
	private String[] GetInfo;
	String[] greeting;
	String[] Delivary;
	private String downprice;
	int[] arr;
	int resalut;
	private Vector<Integer> ItemsToPurchase = new Vector<Integer>();
	public static Vector<Object> OrderDeatails = new Vector<Object>();
	private static int sum = 0; 
	
	public static int calc=0;	
	private JPanel order1 = null;
	
	
	private JLabel jLabelMainOrder = null;
	private JLabel jLabelItemName = null;
	private JComboBox jComboBoxItems = null;
	private JLabel jLabelPrice = null;
	private JTextField jTextFieldStartPrice = null;	
	private JLabel jLabelEndPrice = null;	
	private JTextField jTextFieldEndPrice = null;
	private JLabel jLabelPriceRange = null;
	private JButton jButtonHelp = null;
	private JButton jButtonExit = null;
	private JButton jButtonNext = null;
	private JLabel jLabelColor = null;
	private JComboBox jComboBoxColor = null;
	private JButton jButtonSearch = null;
	private Client order1Chat;
	private JLabel jLabelBackground = null;	
	private DefaultTableModel model1 = new DefaultTableModel();
	private DefaultTableModel model2 = new DefaultTableModel();	
	private JTable jTableResualts = null;
	private JLabel jLabelCart = null;
	private JLabel jLabelCash = null;
	private JTextField jTextFieldSum = null;
	private JLabel jLabelNis = null;
	private JButton jButtonFinishSelecting = null;
	private JLabel jLabelBouqeete = null;
	private JLabel jLabelV = null;
	private JLabel jLabelPic = null;
	/**
	 * This method initializes 
	 * 
	 */ 
	private CustomerCatalog cc;
	private Client c;
	private JTable jTableReasalts = null;
	private JScrollPane jScrollPaneReasalts = null;
	private JTable jTableReasalts1 = null;
	private JScrollPane jScrollPaneSelectedItems = null;
	private JTable jTableSelectedItems = null;
	public Order1() {
		super();		
		initialize();
	}
	
	/**
	 * This method initializes this also initializes the Order2 and Order3 panels
	 * 
	 */
	private void initialize() {
        this.setSize(new Dimension(600, 800));
        this.setContentPane(getOrder1());
        this.setTitle("ORDER");    
        c = new Client(host,DEFAULT_PORT); 
        this.cc = new CustomerCatalog();
        this.order2 = new Order2();        
        order2.setLayout(null);
        order2.setSize(new Dimension(600, 800));
        this.order3 = new Order3();
        order3.setLayout(null);
        order3.setSize(new Dimension(600, 800));
        OrderDeatails.add("order");
        OrderDeatails.add(MainPanel.Userinfo[3]);
        order2.jButtonBack.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				setContentPane(getOrder1());
			}
		});
		order2.jButtonExit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {	
				calc=0;
			Order1.this.dispose();				
			}
		});
		order2.jButtonNext.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				
				int datevalid=0;
				int timevalid=0;
				greeting=new String[2];				
				greeting[0]="greeting";
				greeting[1]=Order2.jTextAreaGreeting.getText();
					OrderDeatails.add(greeting);
					
					if ((((Order2.SelfDelivaryState%2)==0)) && (!((Order2.statecount%2)==0)))
					{
						String[] finalsum = new String[6];
						finalsum[0]="sum";
						if (orderflag==1)
							finalsum[1]=Integer.toString(calc+30);
						if (orderflag==2)
						{
							int sum = 0;
							for (int i=0;i<cc.order.size();i++){
								sum+=cc.order.get(i).getPrice();
							}
							calc=sum;
							finalsum[1]=Integer.toString(calc+30);
						}
						OrderDeatails.add(finalsum);
						
						
					Delivary=new String[6];
					Delivary[0]="delivary";
					Delivary[1]=Order2.jTextFieldStreet.getText();
					Delivary[4]=Order2.jTextFieldReciever.getText();
					Delivary[5]=Order2.jTextFieldPhone.getText();
					
					String daycheck = Order2.jTextFieldDay.getText();
					String monthcheck = Order2.jTextFieldMonth.getText();
					String yearcheck = Order2.jTextFieldYear.getText();
					int day = Integer.parseInt(daycheck.trim());
					int month = Integer.parseInt(monthcheck.trim());
					int year = Integer.parseInt(yearcheck.trim());
					if ((day<0) || (day>31))
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("THE DAY IS INCORRECT");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true ); 	
						Order2.jTextFieldDay.setText(null);
						datevalid++;
					}
					if ((month<0) || (month>12))
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("THE MONTH IS INCORRECT");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true ); 	
						Order2.jTextFieldMonth.setText(null);
						datevalid++;
					}
					if (year!=11)
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("THE YEAR IS INCORRECT");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true ); 	
						Order2.jTextFieldYear.setText(null);
						datevalid++;
					}
					if (datevalid==0)
					{
						StringBuffer sb = new StringBuffer(40); 
						Delivary[2] = sb.append(daycheck).append('.').append(monthcheck).append('.').append(yearcheck).toString();						
					}
					
					
					String hourcheck = Order2.jTextFieldHour.getText();
					String minutecheck = Order2.jTextFieldMinute.getText();
					
					int hour = Integer.parseInt(hourcheck.trim());
					int minute = Integer.parseInt(minutecheck.trim());					
					if ((hour<0) || (hour>24))
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("THE HOUR IS INCORRECT");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true ); 	
						Order2.jTextFieldHour.setText(null);
						timevalid++;
					}
					if ((minute<0) || (minute>60))
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("THE MINUTES ARE INCORRECT");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true ); 	
						Order2.jTextFieldMinute.setText(null);
						timevalid++;
					}
					if (timevalid==0)
					{
						StringBuffer sb = new StringBuffer(40); 
						Delivary[3] = sb.append(hourcheck).append(':').append(minutecheck).toString();						
					}
					
					
					
							if ((timevalid==0)&&(datevalid==0))										
							{
								OrderDeatails.add(Delivary);
								setContentPane(order3);	
							}
					}
					if ((((Order2.SelfDelivaryState%2)==0)) && ((Order2.statecount%2)==0))
					{
						String[] finalsum = new String[2];
						finalsum[0]="sum";
						if (orderflag==1)							
						finalsum[1]=Integer.toString(calc);
						
						if (orderflag==2)
						{
							
							for (int i=0;i<cc.order.size();i++){
								sum+=cc.order.get(i).getPrice();
							}	
							calc=sum;
							finalsum[1]=Integer.toString(calc);
						}
						OrderDeatails.add(finalsum);
						Delivary=new String[6];
						Delivary[0]="no_delivary";
						Delivary[1]="";
						Delivary[2]="";
						Delivary[3]="";
						Delivary[4]="";
						Delivary[5]="";						
						OrderDeatails.add(Delivary);
						
					}
				if ((!((Order2.SelfDelivaryState%2)==0)) && ((Order2.statecount%2)==0))
					{
						String[] finalsum = new String[2];
						finalsum[0]="sum";
						if (orderflag==1)							
						finalsum[1]=Integer.toString(calc);
						
						if (orderflag==2)
						{
							
							for (int i=0;i<cc.order.size();i++){
								sum+=cc.order.get(i).getPrice();
							}	
							calc=sum;
							finalsum[1]=Integer.toString(calc);
						}
						OrderDeatails.add(finalsum);
						Delivary=new String[6];
						Delivary[0]="self-delivary";
						Delivary[1]="";
						Delivary[2]="";
						Delivary[3]="";
						Delivary[4]="";
						Delivary[5]="";						
						OrderDeatails.add(Delivary);
					}
					setContentPane(order3);	
								
			}
		});		
		order3.jButtonExit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {					
			Order1.this.dispose();	
			calc=0;
			}
		});
		order3.jButtonBack.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {					
				setContentPane(order2);				
			}
		});		
	}

	/**
	 * This method initializes order1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getOrder1() {
		if (order1 == null) {		
			jLabelPic = new JLabel();
			jLabelPic.setBounds(new Rectangle(422, 118, 139, 113));			
			jLabelPic.setVisible(false);
			jLabelV = new JLabel();
			ImageIcon imageV = new ImageIcon("v_Icon.gif");						
			jLabelV.setIcon(imageV);
			jLabelV.setBounds(new Rectangle(342, 603, 67, 61));			
			jLabelV.setVisible(false);
			jLabelNis = new JLabel();
			ImageIcon imageNis = new ImageIcon("cost.gif");						
			jLabelNis.setIcon(imageNis);
			jLabelNis.setBounds(new Rectangle(292, 614, 41, 39));
			jLabelNis.setVisible(false);
			jLabelCash = new JLabel();
			ImageIcon imageCash = new ImageIcon("cashbox.png");						
			jLabelCash.setIcon(imageCash);
			jLabelCash.setBounds(new Rectangle(69, 574, 120, 125));
			jLabelCash.setVisible(false);
			jLabelCart = new JLabel();
			ImageIcon imageCart = new ImageIcon("cart_logo.png");						
			jLabelCart.setIcon(imageCart);
			jLabelCart.setBounds(new Rectangle(445, 517, 134, 132));
			jLabelCart.setVisible(false);
			ImageIcon imageOrder = new ImageIcon("order-icon1.gif");
			jLabelColor = new JLabel();
			jLabelColor.setBounds(new Rectangle(30, 286, 121, 32));
			jLabelColor.setText("DOMINATIN COLOR:");
			jLabelPriceRange = new JLabel();
			jLabelPriceRange.setBounds(new Rectangle(235, 193, 92, 32));
			jLabelPriceRange.setText("PRICE RANGE");
			jLabelEndPrice = new JLabel();
			jLabelEndPrice.setBounds(new Rectangle(252, 233, 61, 27));
			jLabelEndPrice.setText("HIGHEST:");
			jLabelPrice = new JLabel();
			jLabelPrice.setBounds(new Rectangle(29, 233, 55, 27));
			jLabelPrice.setText("LOWEST:");
			jLabelItemName = new JLabel();
			jLabelItemName.setBounds(new Rectangle(30, 150, 105, 32));
			jLabelItemName.setText("ITEM TYPE:");
			jLabelMainOrder = new JLabel();
			jLabelMainOrder.setIcon(imageOrder);
			jLabelMainOrder.setBounds(new Rectangle(41, 6, 493, 109));
		//	jLabelMainOrder.setText("MAKE AN ORDER (pic)");
			order1 = new JPanel();
			order1.setLayout(null);
			order1.setBackground(Color.cyan);
			order1.add(jLabelMainOrder, null);
			order1.add(jLabelItemName, null);
			order1.add(getJComboBoxItems(), null);
			order1.add(jLabelPrice, null);
			order1.add(getJTextFieldStartPrice(), null);
			order1.add(jLabelEndPrice, null);
			order1.add(getJTextFieldEndPrice(), null);
			order1.add(jLabelPriceRange, null);
			order1.add(getJButtonHelp(), null);
			order1.add(getJButtonExit(), null);
			order1.add(getJButtonNext(), null);
			order1.add(jLabelColor, null);
			order1.add(getJComboBoxColor(), null);
			order1.add(getJButtonSearch(), null);			
			
			
			
			
			order1.add(jLabelCart, null);
			order1.add(jLabelCash, null);
			order1.add(getJTextFieldSum(), null);
			order1.add(jLabelNis, null);
			order1.add(getJButtonFinishSelecting(), null);
			order1.add(jLabelV, null);
			order1.add(jLabelPic, null);
			order1.add(getJScrollPaneReasalts(), null);
			order1.add(getJScrollPaneSelectedItems(), null);
			
		}
		return order1;
	}

	/**
	 * This method initializes jComboBoxItems	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxItems() {
		if (jComboBoxItems == null) {
			jComboBoxItems = new JComboBox();
			jComboBoxItems.setBounds(new Rectangle(150, 150, 256, 32));			
			jComboBoxItems.addItem("");
			jComboBoxItems.addItem("flower cluster");
			jComboBoxItems.addItem("plant");
			jComboBoxItems.addItem("tree");
			jComboBoxItems.addItem("bridal bouquet");
			jComboBoxItems.addItem("vase");				
		}
		return jComboBoxItems;
	}

	/**
	 * This method initializes jTextFieldStartPrice	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldStartPrice() {
		if (jTextFieldStartPrice == null) {
			jTextFieldStartPrice = new JTextField();
			jTextFieldStartPrice.setBounds(new Rectangle(100, 233, 136, 27));
		}
		return jTextFieldStartPrice;
	}

	/**
	 * This method initializes jTextFieldEndPrice	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldEndPrice() {
		if (jTextFieldEndPrice == null) {
			jTextFieldEndPrice = new JTextField();
			jTextFieldEndPrice.setBounds(new Rectangle(336, 233, 136, 27));
		}
		return jTextFieldEndPrice;
	}

	/**
	 * This method initializes jButtonHelp and opens the help screen
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonHelp() {
		if (jButtonHelp == null) {
			jButtonHelp = new JButton();
			jButtonHelp.setBounds(new Rectangle(20, 706, 106, 45));
			jButtonHelp.setText("HELP");
			jButtonHelp.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					HelpFrame HFrame = new HelpFrame();

					HFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
					HFrame.setSize( 600,720 ); // set frame size
					HFrame.setResizable(false);
					HFrame.setVisible( true ); // display frame
				}
			});
		}
		return jButtonHelp;
	}

	/**
	 * This method initializes jButtonExit and opens the exit screen
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonExit() {
		if (jButtonExit == null) {
			jButtonExit = new JButton();
			jButtonExit.setBounds(new Rectangle(485, 706, 91, 45));
			jButtonExit.setText("EXIT");
			jButtonExit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {					
					jTextFieldSum.setText("");
					calc=0;
					Order1.this.dispose();
				}
			});
		}
		return jButtonExit;
	}

	/**
	 * This method initializes jButtonNext and opens the Order2 panel
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonNext() {
		if (jButtonNext == null) {
			jButtonNext = new JButton();
			jButtonNext.setBounds(new Rectangle(396, 706, 83, 45));
			jButtonNext.setText("NEXT");
			jButtonNext.setVisible(false);
			jButtonNext.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {


					for (int i=1;i<=resalut;i++)
					{
						if (!(arr[i]==0))
						{
							ItemsToPurchase.add(i);
							ItemsToPurchase.add(arr[i]);
						}
					}

					OrderDeatails.add(ItemsToPurchase);
					
					setContentPane(order2);
				}
			});
		}
		return jButtonNext;
	}

	/**
	 * This method initializes jComboBoxColor	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxColor() {
		if (jComboBoxColor == null) {
			jComboBoxColor = new JComboBox();
			jComboBoxColor.setBounds(new Rectangle(169, 286, 147, 32));
			jComboBoxColor.addItem("");
			jComboBoxColor.addItem("Red");
			jComboBoxColor.addItem("Yellow");
			jComboBoxColor.addItem("White");
			jComboBoxColor.addItem("Orange");
			jComboBoxColor.addItem("Green");
			jComboBoxColor.addItem("Purple");
		}
		return jComboBoxColor;
	}

	/**
	 * This method initializes jButtonSearch returns all the items that were searched by he user in a jtable	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonSearch() {
		if (jButtonSearch == null) {
			jButtonSearch = new JButton();
			ImageIcon imageSearch = new ImageIcon("results-logo.jpg");
			jButtonSearch.setIcon(imageSearch);
			jButtonSearch.setBounds(new Rectangle(334, 270, 154, 55));
		//	jButtonSearch.setText("Search");
			jButtonSearch.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					Client SearchIteminOrder = new Client(host,DEFAULT_PORT);
					ArrayList resalts = new ArrayList<String[]>();										
					jTableSelectedItems.setVisible(true);
					jLabelCart.setVisible(true);
					jButtonFinishSelecting.setVisible(true);
					jScrollPaneSelectedItems.setVisible(true);
					jTableSelectedItems.setVisible(true);
					jLabelNis.setVisible(true);
					jLabelCash.setVisible(true);
					jTextFieldSum.setVisible(true);
					
					for( int i = model1.getRowCount() - 1; i >= 0; i-- )					
						model1.removeRow(i);						
					if (jTableReasalts1.isVisible()==false)
					{
						jScrollPaneReasalts.setVisible(true);
						jTableReasalts1.setVisible(true);
					}
					
					Orderinfo = new String[5];					
					Orderinfo[0]="OrderSearch";			
					Orderinfo[1]=(String) jComboBoxItems.getSelectedItem();	
					Orderinfo[2]=jTextFieldStartPrice.getText();
					Orderinfo[3]=jTextFieldEndPrice.getText();
					Orderinfo[4]=(String) jComboBoxColor.getSelectedItem();
					
					if (Orderinfo[1].equals("flower cluster"))
						Orderinfo[1]="flower";
					
					
					if (((Orderinfo[2].equalsIgnoreCase(""))) && ((Orderinfo[3].equalsIgnoreCase(""))) && ((Orderinfo[1].equalsIgnoreCase("")) && ((Orderinfo[4].equalsIgnoreCase("")))) )
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("PLEASE ENTER PARAMATERS FOR SEARCH");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true ); 
						jTextFieldStartPrice.setText(null);
						jTextFieldEndPrice.setText(null);												
						jTableResualts.setVisible(false);
						jTableSelectedItems.setVisible(false);
						jLabelCart.setVisible(false);
						jButtonFinishSelecting.setVisible(false);
						jLabelNis.setVisible(false);
						jLabelCash.setVisible(false);
						jTextFieldSum.setVisible(false);
					}
					
					if ((!(Orderinfo[2].equalsIgnoreCase(""))) && (!(Orderinfo[3].equalsIgnoreCase(""))))
					{
						int check1 = Integer.parseInt(Orderinfo[2].trim());
						int check2 = Integer.parseInt(Orderinfo[3].trim());
					if ((check1<0)||(check2<0))
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("THE PRICE RANGE IS INCORRECT");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true ); 	
						jTextFieldStartPrice.setText(null);
						jTextFieldEndPrice.setText(null);												
						jTableResualts.setVisible(false);
						jTableSelectedItems.setVisible(false);
						jLabelCart.setVisible(false);
						jButtonFinishSelecting.setVisible(false);
						jLabelNis.setVisible(false);
						jLabelCash.setVisible(false);
						jTextFieldSum.setVisible(false);
					}
					else
					{
					SearchIteminOrder.accept(Orderinfo);
					Object p = SearchIteminOrder.getMsg();
					resalts = (ArrayList)p;
					
									
					for (int i=0;i<=resalts.size();i++)
					{
						String[] DataToTable = (String[]) resalts.get(i);
						model1.insertRow(i, DataToTable);
					}
										
				}
					}
					
					if (((Orderinfo[2].equalsIgnoreCase(""))) && (!(Orderinfo[3].equalsIgnoreCase(""))))
					{
	
						int check2 = Integer.parseInt(Orderinfo[3].trim());
					if ((check2<0))
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("THE PRICE RANGE IS INCORRECT");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true ); 	
						jTextFieldStartPrice.setText(null);
						jTextFieldEndPrice.setText(null);												
						jTableResualts.setVisible(false);
						jTableSelectedItems.setVisible(false);
						jLabelCart.setVisible(false);
						jButtonFinishSelecting.setVisible(false);
						jLabelNis.setVisible(false);
						jLabelCash.setVisible(false);
						jTextFieldSum.setVisible(false);
					}
					else
					{
					SearchIteminOrder.accept(Orderinfo);
					Object p = SearchIteminOrder.getMsg();
					resalts = (ArrayList)p;
					
									
					for (int i=0;i<=resalts.size();i++)
					{
						String[] DataToTable = (String[]) resalts.get(i);
						model1.insertRow(i, DataToTable);
					}
										
				}
					}
					
					if (((Orderinfo[2].equalsIgnoreCase(""))) && ((Orderinfo[3].equalsIgnoreCase(""))))
					{
					SearchIteminOrder.accept(Orderinfo);
					Object p = SearchIteminOrder.getMsg();
					resalts = (ArrayList)p;
					
									
					for (int i=0;i<=resalts.size();i++)
					{
						String[] DataToTable = (String[]) resalts.get(i);
						model1.insertRow(i, DataToTable);
					}
										
				
					}
					
					
					
					
					if ((!(Orderinfo[2].equalsIgnoreCase(""))) && ((Orderinfo[3].equalsIgnoreCase(""))))
					{
						int check1 = Integer.parseInt(Orderinfo[2].trim());
						
					if ((check1<0))
					{
						ErrorFrame EFrame = new ErrorFrame();
						EFrame.jLabelMassage.setText("THE PRICE RANGE IS INCORRECT");
						EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
						EFrame.setSize( 380,217 ); // set frame size
						EFrame.setResizable(true);
						EFrame.setVisible( true ); 	
						jTextFieldStartPrice.setText(null);
						jTextFieldEndPrice.setText(null);												
						jTableResualts.setVisible(false);
						jTableSelectedItems.setVisible(false);
						jLabelCart.setVisible(false);
						jButtonFinishSelecting.setVisible(false);
						jLabelNis.setVisible(false);
						jLabelCash.setVisible(false);
						jTextFieldSum.setVisible(false);
					}
					else
					{
					SearchIteminOrder.accept(Orderinfo);
					Object p = SearchIteminOrder.getMsg();
					resalts = (ArrayList)p;
					
									
					for (int i=0;i<=resalts.size();i++)
					{
						String[] DataToTable = (String[]) resalts.get(i);
						model1.insertRow(i, DataToTable);
					}
										
				}
					}	
					
					
				}
			});
		}
		return jButtonSearch;
	}

	/**
	 * This method initializes jTableResualts	
	 * 	
	 * @return javax.swing.JTable	
	 */
	

	/**
	 * This method initializes jTextFieldSum	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldSum() {
		if (jTextFieldSum == null) {
			jTextFieldSum = new JTextField();
			jTextFieldSum.setBounds(new Rectangle(194, 609, 93, 47));
			jTextFieldSum.setVisible(false);
		//	jTextFieldSum.setText(Integer.toString(calc));
			jTextFieldSum.setText("");
		}
		return jTextFieldSum;
	}

	/**
	 * This method initializes jButtonFinishSelecting and checks if all the items are in the inventory
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonFinishSelecting() {
		if (jButtonFinishSelecting == null) {
			jButtonFinishSelecting = new JButton();
			ImageIcon imageToCart = new ImageIcon("right-arrow-icon.jpg");
			jButtonFinishSelecting.setIcon(imageToCart);
			jButtonFinishSelecting.setBounds(new Rectangle(450, 465, 77, 48));
			jButtonFinishSelecting.setVisible(false);
			jButtonFinishSelecting.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					int state=0;
					Client NumOfItems = new Client(host,DEFAULT_PORT);
					String num_of_itmes="num_of_items";
					NumOfItems.accept(num_of_itmes);
					Object p = NumOfItems.getMsg();
					resalut = (Integer)p;
					arr = new int[resalut+1];
					for (int i=0;i<resalut;i++)
						arr[i]=0;
					for (int j=0;j<model2.getRowCount();j++)
					{
						String aa = (String)model2.getValueAt(j, 0);	
						int index = Integer.parseInt(aa.trim());
						arr[index]++;
					}
					String[] ChkInInventory = new String[3];
					ChkInInventory[0]= "check_inventory";
					for (int i=1;i<=resalut;i++)
					{
						if (!(arr[i]==0))
						{
							ChkInInventory[1]=Integer.toString(i);
							ChkInInventory[2]=Integer.toString(arr[i]);
						//	System.out.println(i+" "+ arr[i]);
							NumOfItems.accept(ChkInInventory);
							Object k = NumOfItems.getMsg();
							String[] answer = (String[])k;
							int r = Integer.parseInt(answer[0].trim());
							if (r==1)
							{
								state++;
								ErrorFrame EFrame = new ErrorFrame();
								EFrame.jLabelMassage.setText("THERE ISNT ENOUGH "+answer[1]+" IN THE INVENTORY");
								EFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
								EFrame.setSize( 380,217 ); // set frame size
								EFrame.setResizable(true);
								EFrame.setVisible( true ); 
							}
						}
					}
					if (state==0)
					{
					jLabelV.setVisible(true);
					jButtonNext.setVisible(true);
					}
					
					
				}
			});
		}
		return jButtonFinishSelecting;
	}

	/**
	 * This method initializes jScrollPaneReasalts	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPaneReasalts() {
		if (jScrollPaneReasalts == null) {
			jScrollPaneReasalts = new JScrollPane();
			jScrollPaneReasalts.setBounds(new Rectangle(32, 326, 510, 121));
			jScrollPaneReasalts.setViewportView(getJTableReasalts1());
			jScrollPaneReasalts.setVisible(false);
		}
		return jScrollPaneReasalts;
	}

	/**
	 * This method initializes jTableReasalts1	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTableReasalts1() {
		if (jTableReasalts1 == null) {
			jTableReasalts1 = new JTable(model1);
			model1.addColumn("ID");
			model1.addColumn("Name");
			model1.addColumn("Category");
			model1.addColumn("Descreption");
			model1.addColumn("Price");	
			jTableReasalts1.setVisible(false);
			jTableReasalts1.setBounds(new Rectangle(44, 586, 510, 160));
			jTableReasalts1.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent e) {
				int row = jTableReasalts1.getSelectedRow();
				int col = jTableReasalts1.getSelectedColumn();				
				String item_num=(java.lang.String) model1.getValueAt(row, 0);
				String[] pic = new String[2];
				pic[0]="get_pic";
				pic[1]=item_num;
				Client GetPic = new Client(host,DEFAULT_PORT);
				GetPic.accept(pic);
				Object p = GetPic.getMsg();
				Item resalts = (Item)p;
				jLabelPic.setVisible(true);
								
				jLabelPic.setIcon(resalts.getIcon());
				
				GetInfo = new String[4];
				for (int i=0;i<3;i++)				
				GetInfo[i]=(String) model1.getValueAt(row, i);
				GetInfo[3]=(String) model1.getValueAt(row, 4);
				model2.insertRow(model2.getRowCount(), GetInfo);
				int calc1 = Integer.parseInt(GetInfo[3].trim());
				calc=calc+calc1;				
					jTextFieldSum.setText(Integer.toString(calc));				
				}
				}); 
		}
		return jTableReasalts1;
	}

	/**
	 * This method initializes jScrollPaneSelectedItems	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPaneSelectedItems() {
		if (jScrollPaneSelectedItems == null) {
			jScrollPaneSelectedItems = new JScrollPane();
			jScrollPaneSelectedItems.setBounds(new Rectangle(32, 450, 403, 122));
			jScrollPaneSelectedItems.setViewportView(getJTableSelectedItems());
			jScrollPaneSelectedItems.setVisible(false);
		}
		return jScrollPaneSelectedItems;
	}

	/**
	 * This method initializes jTableSelectedItems	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTableSelectedItems() {
		if (jTableSelectedItems == null) {
			jTableSelectedItems = new JTable(model2);
			
			model2.addColumn("ID");
			model2.addColumn("Name");
			model2.addColumn("Category");			
			model2.addColumn("Price");
			jTableSelectedItems.setVisible(false);
			jTableSelectedItems.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent e) {
				int row = jTableSelectedItems.getSelectedRow();							
				downprice=(String) model2.getValueAt(row, 3);
				int calc2 = Integer.parseInt(downprice.trim());
				calc=calc-calc2;
				jTextFieldSum.setText(Integer.toString(calc));
				model2.removeRow(row);		
				}
				}); 
		}
		return jTableSelectedItems;
	}
	
	
	

}  //  @jve:decl-index=0:visual-constraint="10,10"
